package com.hzdl.house_mgr.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzdl.house_mgr.bean.BaseStat;
import com.hzdl.house_mgr.bean.User;
import com.hzdl.house_mgr.mapper.UserMapper;
import com.hzdl.house_mgr.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo<User> findAll(User user,Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<User> all = userMapper.findAll(user);
        return new PageInfo<User>(all);
    }

    @Override
    public int getCount(User user) {
        return userMapper.getCount(user);
    }

    @Override
    public int userAdd(User user) {
        return userMapper.userAdd(user);
    }

    @Override
    public int userUpd(User userId) {
        return userMapper.userUpd(userId);
    }

    @Override
    public int del(Integer userId) {
        return userMapper.del(userId);
    }

    @Override
    public int delSome(String[] split) {
        int row=0;
        if(split != null && split.length != 0){
            for(String userId : split){
                row += userMapper.del(Integer.parseInt(userId));
            }
        }
        return row;
    }

    @Override
    public List<BaseStat> getCountByAddress() {
        return userMapper.getCountByAddress();
    }

    @Override
    public int findUserById(String idCard) {
        return userMapper.findUserById(idCard);
    }

    @Override
    public int register(User user) {
        return userMapper.register(user);
    }

    @Override
    public User chkLoginNameAndUserPwd(String loginName, String userPwd) {
        return userMapper.chkLoginNameAndUserPwd(loginName,userPwd);
    }

    @Override
    public User findUserByFace(String faceId) {
        return userMapper.findUserByFace(faceId);
    }

    @Override
    public User findUserByUserId(Integer userId) {
        return userMapper.findUserByUserId(userId);
    }

    @Override
    public int resetUserPwd(Integer userId) {
        return userMapper.resetUserPwd(userId);
    }

    @Override
    public User chkLoginIdExits(String loginName) {
        return userMapper.chkLoginIdExits(loginName);
    }
}
